using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Entities;
namespace DAL
{
    public class tbPhuongThucThanhToanDAL
    {
        private SqlConnection cn = null;
        public tbPhuongThucThanhToanDAL()
        {
            cn = new SqlConnection(ConfigurationManager.ConnectionStrings["strConnection"].ConnectionString);
            cn.Open();
        }

        public tbPhuongThucThanhToanDAL(tbPhuongThucThanhToanDAL phuongthucthanhtoan)
        {
            this.cn = new SqlConnection(ConfigurationManager.ConnectionStrings["strConnection"].ConnectionString);
            this.cn.Open();
        }

        public void Insert(tbPhuongThucThanhToan phuongthucthanhtoan)
        {
            SqlCommand cm = new SqlCommand("sp_tbPhuongThucThanhToan_insert", cn);
            cm.CommandType = CommandType.StoredProcedure;
            cm.Parameters.AddWithValue("@TenPTTT", phuongthucthanhtoan.TenPTTT);
            cm.Parameters.AddWithValue("@Hinh", phuongthucthanhtoan.Hinh);
            cm.ExecuteNonQuery();
        }
        public void Update(tbPhuongThucThanhToan phuongthucthanhtoan)
        {
            SqlCommand cm = new SqlCommand("sp_tbPhuongThucThanhToan_update", cn);
            cm.CommandType = CommandType.StoredProcedure;
            cm.Parameters.AddWithValue("@MaPTTT", phuongthucthanhtoan.MaPTTT);
            cm.Parameters.AddWithValue("@TenPTTT", phuongthucthanhtoan.TenPTTT);
            cm.Parameters.AddWithValue("@Hinh", phuongthucthanhtoan.Hinh);
            cm.ExecuteNonQuery();
        }
        public void Delete(int iD)
        {
            SqlCommand cm = new SqlCommand("sp_tbPhuongThucThanhToan_delete", cn);
            cm.CommandType = CommandType.StoredProcedure;
            cm.Parameters.AddWithValue("@MaPTTT", iD);
            cm.ExecuteNonQuery();
        }
        public tbPhuongThucThanhToanCollection Get(string where, int pageIndex, int pageSize,
            string orderBy, string orderDirection, out int totalRecords)
        {
            SqlCommand cm = new SqlCommand("sp_tbPhuongThucThanhToan_get", cn);
            cm.CommandType = CommandType.StoredProcedure;
            cm.Parameters.AddWithValue("@Where", where);
            cm.Parameters.AddWithValue("@PageIndex", pageIndex);
            cm.Parameters.AddWithValue("@PageSize", pageSize);
            cm.Parameters.AddWithValue("@OrderBy", orderBy);
            cm.Parameters.AddWithValue("@OrderDirection", orderDirection);
            cm.Parameters.Add(new SqlParameter("@TotalRecords", DbType.Int32)).Direction = ParameterDirection.Output;

            SqlDataReader dr = cm.ExecuteReader();
            tbPhuongThucThanhToanCollection ptttCollection = new tbPhuongThucThanhToanCollection();

            while (dr.Read())
            {
                tbPhuongThucThanhToan phuongthucthanhtoan = new tbPhuongThucThanhToan();
                phuongthucthanhtoan.MaPTTT = int.Parse(dr.GetValue(0).ToString());
                phuongthucthanhtoan.TenPTTT = dr.GetValue(1).ToString();
                phuongthucthanhtoan.Hinh = dr.GetValue(2).ToString();
                ptttCollection.Add(phuongthucthanhtoan);
            }
            dr.Close();
            totalRecords = int.Parse(cm.Parameters["@TotalRecords"].Value.ToString());
            return ptttCollection;
        }
    }
}